package com.example.administrator.daydayappmarket.list.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.list.adapter.ListFramentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListFragment extends Fragment {


    @InjectView(R.id.fragment_list_viewPager)
    ViewPager viewPager;
    @InjectView(R.id.fragment_list_tablayout)
    TabLayout tablayout;



    private ListFramentPagerAdapter adapter;
    private List<Fragment> fragments;


    public ListFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_list, container, false);
        ButterKnife.inject(this, view);

        initView();

        adapter=new ListFramentPagerAdapter(getChildFragmentManager(),fragments);
        viewPager.setAdapter(adapter);
        tablayout.setupWithViewPager(viewPager);

        return view;
    }

    private void initView() {
        fragments = new ArrayList<>();
        fragments.add(new ListSolftFragment());
        fragments.add(new ListGameFragment());


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
